<template>
	<basic-container>
		<avue-crud
			:option="option"
			:data="data"
			ref="crud"
			v-model="form"
			:table-loading="loading"
			:permission="permissionList"
			:page="page"
			@refresh-change="refreshChange"
			@search-change="searchChange"
			@search-reset="searchReset"
			@current-change="currentChange"
			@size-change="sizeChange"
			@selection-change="selectionChange"
			@on-load="onLoad"
		>
			<template slot-scope="scope" slot="menu">
				<el-button icon="el-icon-view" type="text" size="small" @click="viewDetail(scope.row.id, scope.row.userName,scope.row.storeWillCallId,)" v-has="'/mall-cloud-order/orderForm/detail'">
					查看详情
				</el-button>
				<el-button icon="el-icon-view" type="text" size="small" @click="viewOrderGoods(scope.row.id)" v-has="'/mall-cloud-order/orderForm/detail'">
					查看订单商品
				</el-button>
			</template>

		<!-- 	<template slot="expand" slot-scope="{ row }">

			</template> -->
			<template slot-scope="{ row }" slot="totalPrice">
				<div>
					<p>{{ row.totalPrice }}</p>
				</div>
			</template>
			<!-- 自定义添加搜索条件  按日期搜索  -->
			<template slot="search">
				<el-col :md="24" :xs="12" style="width: 50%;float: left;">
					<el-form-item label="下单时间" style="width: 50%;display: inline-block;">
						<el-date-picker size="mini" placeholder="开始时间" @change="getBeginTime" value-format="yyyy-MM-dd HH:mm:ss" v-model="addTimeBegin" type="datetime"></el-date-picker>
					</el-form-item>
					<el-form-item label="至" style="width: 50%;display: inline-block;">
						<el-date-picker size="mini" placeholder="结束日期" @change="getEndTime" value-format="yyyy-MM-dd HH:mm:ss" v-model="addTimeEnd" type="datetime"></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="12" style="display: flex;">
				    <el-form-item label="业务发生区域" label-width="100px" style="display: inline-block;">
				        <el-select size="small" v-model="rareaId" placeholder="区域"
				                   @change="changeAreaForRongChuang(rareaId,3)">
				            <el-option v-for="item in rareas" :key="item.id" :label="item.name"
				                       :value="item.id">
				            </el-option>
				        </el-select>
				    </el-form-item>
				    <el-form-item 　label-width="10px" style="display: inline-block;">
				        <el-select size="small" v-model="rcityId" placeholder="城市"
				                   @change="changeAreaForRongChuang(rcityId,4)">
				            <el-option v-for="item in rcitys" :key="item.id" :label="item.name"
				                       :value="item.id">
				            </el-option>
				        </el-select>
				    </el-form-item>
				    <el-form-item 　label-width="10px" style="display: inline-block;">
				        <el-select size="small" v-model="projectId" placeholder="项目"
				                   @change="changeAreaForRongChuang(projectId,5)">
				            <el-option v-for="item in projects" :key="item.id" :label="item.name"
				                       :value="item.id">
				            </el-option>
				        </el-select>
				    </el-form-item>
				</el-col>
			</template>
			<template slot="searchMenu">
<!--				<el-button type="primary" size="mini" @click="outExcel">导出订单</el-button>-->
				<el-button type="primary" size="mini" @click="outLittleExcel">部分导出</el-button>
				<el-button type="primary" size="mini" @click="outOrderGoodsExcel">导出订单</el-button>
			</template>
			<!--			<template slot="search">-->
			<!--				<el-col  :span="6" >-->
			<!--					<el-form-item label="订单类型">-->
			<!--						<el-select v-model="orderType" size="mini" >-->
			<!--							<el-option key="普通订单" label="普通订单" value="1"></el-option>-->
			<!--							<el-option key="积分订单" label="积分订单" value="2"></el-option>-->
			<!--						</el-select>-->
			<!--					</el-form-item>-->
			<!--				</el-col>-->
			<!--			</template>-->
		</avue-crud>
		<el-col class="btnRow" :span="8">
			<span class="allMoney">订单总实付金额：{{allMoney}}</span>
		</el-col>
		<el-drawer title="订单商品详情" :before-close="closeOrderGoods" :with-header="false" :visible.sync="dialogOrderGoodsVisible" size="88%">
			<div class="demo-drawer__header">
				<div class="drawerHeader">
					<strong>订单商品详情</strong>
				</div>
			</div>
			<avue-crud ref="crudOrderGood" v-model="orderGood" :option="option1" v-if="orderFormGoodsResults.length>0"  :data="orderFormGoodsResults" :row-style="rowStyle">
				<template slot-scope="{ row }" slot="goodsMainPhotoUrl">
					<img :src="row.goodsMainPhotoUrl" style="width:50px;height:50px;" />
				</template>
				<template slot-scope="{ row }" slot="goodsName">
					<div>
						{{ row.goodsName }}
						<span style="color: red;" v-if="row.acType == 8">[赠品]</span>
					</div>
				</template>
			</avue-crud>
			<div v-else class="loading_icon"><i class="el-icon-loading"></i></div>
		</el-drawer>
		<el-drawer title="订单详情" :with-header="false" :visible.sync="dialogDeatilVisible" size="88%">
			<avue-form :option="optionDetail" v-model="form1">
				<template slot="group1Header">
					<h4 class="avue-group__title">订单详情</h4>
				</template>
				<template slot="group2Header">
					<h4 class="avue-group__title">卖家信息</h4>
				</template>
				<template slot="group3Header">
					<h4 class="avue-group__title">配货单信息</h4>
				</template>
				<template slot="group4Header">
					<h4 class="avue-group__title">优惠信息</h4>
				</template>
				<template slot="group5Header">
					<h4 class="avue-group__title">收货地址</h4>
				</template>
				<template slot="group6Header">
					<h4 class="avue-group__title">支付信息</h4>
				</template>
				<template slot="group7Header">
					<h4 class="avue-group__title">门店自提信息</h4>
				</template>
				<template slot="group8Header">
					<h4 class="avue-group__title">操作历史</h4>
				</template>
				<template slot-scope="scope" slot="menuForm">
					<el-button @click="closeDetailDialog">关闭</el-button>
				</template>

				<template slot-scope="scope" slot="coupon">
					<div>
						<p>
							运费：
							<span style="padding: 0 0.3rem;">{{ form1.actualShipmentAmount }}</span>
						</p>
						<p v-if="form1.orderType != 2">
							店铺优惠：
							<span style="padding: 0 0.3rem;">{{ form1.couponAmountStore }}</span>
						</p>
						<p v-if="form1.orderType != 2">
							平台优惠：
							<span style="padding: 0 0.3rem;">{{ form1.couponAmountPlatform }}</span>
						</p>
						<!-- <p v-if="form1.fullCutAmount > 0">满减优惠：<span style="padding: 0 0.3rem;">{{form1.fullCutAmount}}</span></p>
						<p v-if="form1.fullDiscountAmount > 0">满折优惠：<span style="padding: 0 0.3rem;">{{form1.fullDiscountAmount}}</span></p> -->
						<p v-if="form1.orderType != 2">
							订单总价：
							<span style="padding: 0 0.3rem;">{{ form1.totalPrice }}</span>
						</p>
						<p v-if="form1.orderType != 2">
							总付款：
							<span style="padding: 0 0.3rem;">{{ form1.lastAmount }}</span>
						</p>
						<p v-if="form1.orderType == 2">
							总付积分：
							<span style="padding: 0 0.3rem;">{{ form1.lastAmount }}</span>
						</p>
						<p v-if="form1.storeReward != null">
							商家奖励团长金额：
							<span style="padding: 0 0.3rem;">{{ form1.storeReward }}</span>
						</p>
						<p v-if="form1.platformReward != null">
							平台奖励团长金额：
							<span style="padding: 0 0.3rem;">{{ form1.platformReward }}</span>
						</p>
					</div>
				</template>

				<template slot-scope="scope" slot="goodsDetails">
					<avue-crud :data="form1.goodsDetail" :option="option1">
						<template slot-scope="{ row }" slot="goodsMainPhotoUrl">
							<img :src="row.goodsMainPhotoUrl" style="width:50px;height:50px;" />
						</template>
						<template slot-scope="{ row }" slot="goodsName">
							<div>
								{{ row.goodsName }}
								<span style="color: red;" v-if="row.acType == 8">[赠品]</span>
							</div>
						</template>
					</avue-crud>
				</template>

				<template slot-scope="scope" slot="invoiceType">
					<div>
						<p v-if="form1.invoiceType == 0">个人</p>
						<p v-if="form1.invoiceType == 1">单位</p>
						<p v-if="form1.invoiceType == 2">不开发票</p>
					</div>
				</template>
				<template slot-scope="scope" slot="invoiceTitle">
					<p>{{ form1.invoiceTitle }}</p>
				</template>
				<template slot-scope="scope" slot="invoiceNum">
					<p>{{ form1.invoiceTaxNum }}</p>
				</template>
				<template slot-scope="scope" slot="invoiceEmail">
					<p>{{ form1.invoiceEmail }}</p>
				</template>
				<template slot-scope="scope" slot="invoiceUploadResultMsg">
					<p>{{ form1.invoiceUploadResultMsg }}</p>
				</template>

				<template slot-scope="scope" slot="history">
					<div style="padding: 0.2rem;">
						<p v-for="item in form1.historyLog" :key="item.id">
							<span style="padding: 0 0.1rem;" v-if="item.stateInfo">{{ item.stateInfo }}：</span>
							<span style="color: #ff9900;padding: 0 0.2rem;">{{ item.userName }}</span>
							<span style="padding: 0 0.1rem;" v-if="item.stateInfo == '订单取消'">
								于
								<span style="padding: 0 0.1rem;">{{ item.addTime }}</span>
								取消订单
								<p style="padding: 0 0.1rem;">取消原因：{{ item.logInfo }}</p>
							</span>
							<span style="padding: 0 0.1rem;" v-else>
								于
								<span style="padding: 0 0.1rem;">{{ item.addTime }}</span>
								{{ item.logInfo }}
							</span>
						</p>
					</div>
				</template>

				<template slot-scope="scope" slot="distributionSn">
					<div>
						<div class="distribution" v-if="form1.orderDistributionList.length == 0">暂无配货单信息</div>
						<div class="distribution" v-for="item in form1.orderDistributionList" :key="item.id">
							<el-form :model="item">
								<el-form-item>
									<span style="padding: 0.1rem 0.5rem">配货单号：{{ item.distributionSn }}</span>
									<span style="padding: 0.1rem 0.5rem">生成时间：{{ item.addTime }}</span>
									<span style="padding: 0.1rem 0.5rem" v-if="item.status == 0">配货单状态：未发货</span>
									<span style="padding: 0.1rem 0.5rem" v-if="item.status == 1">配货单状态：已发货</span>
									<span style="padding: 0.1rem 0.5rem" v-if="item.status == 2">配货单状态：已完成</span>
									<span style="padding: 0.1rem 0.5rem" v-if="item.status == 3">配货单状态：已退款</span>
									<span style="padding: 0.1rem 0.5rem" v-if="item.status == 4">配货单状态：已收货</span>
									<span style="padding: 0.1rem 0.5rem" v-if="item.status == -1">配货单状态：退款审核</span>
								</el-form-item>
								<el-form-item v-if="item.orderFormGoodsResultList.length > 0">
									<avue-crud ref="crud2" :option="option1" :data="item.orderFormGoodsResultList">
										<template slot-scope="{ row }" slot="goodsMainPhotoUrl">
											<img :src="row.goodsMainPhotoUrl" style="width:50px;height:50px;" />
										</template>
										<template slot-scope="{ row }" slot="goodsName">
											<div>
												{{ row.goodsName }}
												<span style="color: red;" v-if="row.acType == 8">[赠品]</span>
											</div>
										</template>
									</avue-crud>
								</el-form-item>
								<el-form-item v-else>
									<avue-crud ref="crud2" :option="option1" :data="form1.goodsDetail">
										<template slot-scope="{ row }" slot="goodsMainPhotoUrl">
											<img :src="row.goodsMainPhotoUrl" style="width:50px;height:50px;" />
										</template>
										<template slot-scope="{ row }" slot="goodsName">
											<div>
												{{ row.goodsName }}
												<span style="color: red;" v-if="row.acType == 8">[赠品]</span>
											</div>
										</template>
									</avue-crud>
								</el-form-item>
								<!--<el-form-item v-if="item.orderFormGoodsResultList.length !=0">-->
								<!--<avue-crud ref="crud2" :option="option1" :data="form1.goodsDetail">-->
								<!--<template slot-scope="{row}" slot="goodsMainPhotoUrl">-->
								<!--<img :src="row.goodsMainPhotoUrl" style="width:50px;height:50px;" />-->
								<!--</template>-->
								<!--</avue-crud>-->
								<!--</el-form-item>-->
								<el-form-item v-if="form1.expressType == 1">
									<p>物流公司：{{ item.ecName }}</p>
									<p>物流单号：{{ item.shipCode }}</p>
									<span v-if="item.expressInfoBean != '' && item.expressInfoBean != undefined && item.expressInfoBean != null">
										<el-steps direction="vertical" :active="item.expressInfoBean.data.length">
											<el-step
												v-for="(obj, index) in item.expressInfoBean.data"
												icon="el-icon-success"
												:key="index"
												style="padding: 0.2rem;"
												:description="obj.time + obj.context"
											></el-step>
										</el-steps>
									</span>
								</el-form-item>
							</el-form>
						</div>
					</div>
				</template>

				<!---->
			</avue-form>
		</el-drawer>
	</basic-container>
</template>

<script>
import { getList, getDetail, getOrderFormGoods ,getStoreWillCallId,getCallbackIdByPayFormId} from '@/api/order/orderForm';
import { mapGetters } from 'vuex';
import {
	getOrganizationListByLevel
} from "@/api/admin/area";
import { getToken } from '@/util/store';
var Dict = JSON.parse(localStorage.getItem('mall-dictionary')).content;
var orderStatusEnum = []
Dict.orderStatusEnum.forEach(item=>{
	if(item.label!='待审核'&&item.label!='待评价'){
		orderStatusEnum.push(item)
	}
})
let ReconciliationStatusEnum = [
	{
		label: '未对账',
		value: 1
	},
	{
		label: '已对账',
		value: 2
	}
];
export default {
	data() {
		return {
			cityId: null,
			rareaId: null,
			rcityId: null,
			projectId: null,
			area: '',
			city: '',
			project: '',
			areas: [],
			citys: [],
			projects: [],
			rareas: [],
			rcitys: [],
			idList: [],
			allMoney:0,
			orderType: '1', //是否是积分订单
			form: {},
			form1: {},
			query: {},
			loading: true,
			dialogDeatilVisible: false,
			rolesTree: [],
			rolesKeys: [],
			box: false,
			page: {
				pageSize: 10,
				currentPage: 1,
				total: 0
			},
			//查看详情
			optionDetail: {
				size: 'mini',
				submitBtn: false,
				emptyBtn: false,
				labelWidth: '100',
				group: [
					{
						prop: 'group1',
						column: [
							{
								label: '订单编号',
								prop: 'orderId',
								type: 'text',
								span:8,
								disabled: true,
							},
							{
								label: '订单状态',
								type: 'select',
								prop: 'orderStatus',
								disabled: true,
								span:8,
								dicData: orderStatusEnum
							},
							{
								label: '买家名称',
								prop: 'userName',
								disabled: true,
								span:8,
							},
							{
								label: '下单时间',
								prop: 'addTime',
								disabled: true,
								span:8,
							},
							{
								label: '支付时间',
								prop: 'oPayTime',
								disabled: true,
								span:8,
							},
							{
								label: '支付方式',
								prop: 'payWay',
								type: 'select',
								dicData: Dict.payWayEnum,
								disabled: true,
								span:8,
							},
							{
								label: '配送方式',
								prop: 'expressType',
								disabled: true,
								type: 'select',
								span:8,
								dicData: Dict.expressTypeEnum,
							},
							{
								label: '业务发生区域',
								labelWidth: 100,
								span:8,
								prop: 'regionalOrganizationStr',
								disabled: true,
							},
							{
								label: '业务发生单元',
								labelWidth: 100,
								span:8,
								prop: 'businessUnitOrganizationStr',
								disabled: true,
							},
							{
								label: '业务发生项目',
								labelWidth: 100,
								span:8,
								prop: 'itemOrganizationStr',
								disabled: true,
							}
						]
					},
					{
						//卖家信息
						prop: 'group2',
						column: [
							{
								label: '店铺名称',
								prop: 'storeName',
								disabled: true,
								span:8,
							},
							{
								label: '店铺账号ID',
								prop: 'tripartiteStoreId',
								disabled: true,
								span:8,
							},
							{
								label: '店铺类型',
								prop: 'storeTypeName',
								disabled: true,
								span:8,
							},
							{
								label: '卖家名称',
								prop: 'storeName',
								disabled: true,
								span:8,
							},
							{
								label: '电话号码',
								prop: 'sellerPhoneNumber',
								disabled: true,
								span:8,
							},
							{
								label: '详细地址',
								prop: 'sellerAddress',
								disabled: true,
								span:12,
							}
						]
					},
					{
						//配货单信息
						prop: 'group3',
						column: [
							{
								prop: 'distributionSn',
								formslot: true,
								span: 24
							}
						]
					},
					{
						//优惠信息
						prop: 'group4',
						column: [
							{
								prop: 'coupon',
								formslot: true
							}
						]
					},
					{
						//收货地址
						prop: 'group5',
						column: [
							{
								label: '收货人',
								prop: 'trueName',
								disabled: true,
								span:8,
							},
							{
								label: '收货地址',
								prop: 'address',
								disabled: true,
								span:8,
							},
							{
								label: '详细地址',
								prop: 'areaInfo',
								disabled: true,
								span:8,
							},
							{
								label: '电话号码',
								prop: 'mobile',
								disabled: true,
								span:8,
							},
							{
								label: '买家留言',
								prop: 'buyerMsg',
								disabled: true,
								span:8,
							},
							{
								label: '发票类型',
								prop: 'invoiceType',
								formslot: true,
								display: true,
								span:8,
							},
							{
								label: '发票抬头',
								prop: 'invoiceTitle',
								display: true,
								formslot: true,
								span:8,
							},
							{
								label: '纳税人识别号',
								prop: 'invoiceNum',
								labelWidth: 120,
								display: true,
								formslot: true,
								span:8,
							},
							{
								label: '收件邮箱',
								prop: 'invoiceEmail',
								display: true,
								formslot: true,
								span:8,
							},
							{
								label: '开票结果',
								prop: 'invoiceUploadResultMsg',
								display: true,
								formslot: true,
								span:8,
							}
						]
					},
					{
						//收货地址
						prop: 'group6',
						column: [
							{
								label: '支付单号',
								prop: 'pfCode',
								disabled: true,
								span:8,
							},
							{
								label: '三方订单号',
								prop: 'callbackId',
								disabled: true,
								span:8,
							},
						]
					},
					{
						//门店自提信息
						prop: 'group7',
						display: false,
						column: [
							{
								label: '配货单号',
								prop: 'distributionSn',
								disabled: true,
								span:8,
							},
							{
								label: '自提时间',
								prop: 'storeWillCallTime',
								disabled: true,
								span:8,
							},
							{
								label: '门店信息',
								prop: 'storeWillInfo',
								disabled: true,
								span:8,
							},
							{
								label: '门店地址',
								prop: 'storeWilladdress',
								disabled: true,
								span:8,
							},
							{
								label: '门店电话',
								prop: 'phone',
								disabled: true,
								span:8,
							},
							{
								label: '操作说明',
								prop: 'distributionDesc',
								disabled: true,
								span:8,
							}
						]
					},
					{
						//操作历史
						prop: 'group8',
						column: [
							{
								prop: 'history',
								formslot: true,
								span: 24
							}
						]
					}
				]
			},
			option: {
				size: 'mini',
				tip: true,
				border: true,
				height: 'auto',
				dialogType: 'dialog',
				rowKey: 'orderId',
				defaultExpandAll: false,
				align: 'center',
				menuWidth: 200,
				addBtn: false,
				editBtn: false,
				delBtn: false,
				selection: true,
				column: [
					{
						label: '订单编号',
						prop: 'orderId',
						width: 160,
						searchSpan:8,
						search: true
					},
					{
						label: '订单状态',
						prop: 'orderStatus',
						type: 'select',
						search: true,
						width: 100,
						searchSpan:8,
						disabled: true,
						dicData: orderStatusEnum
					},
					{
						label: '收货人姓名',
						prop: 'addressTrueName',
						width: 130,
						searchSpan:8,
						searchLabelWidth:90,
						search: true
					},
					{
						label: '联系方式',
						prop: 'addressMobile',
						width: 100,
						searchSpan:8,
						search: true
					},
					{
						label: '收货地址',
						prop: 'addressAreaInfo',
						width: 200
					},
					{
						label: '买家实付金额',
						prop: 'lastTotalAmount',
						width: 100
					},
					{
						label: '是否为业主',
						prop: 'user1',
						width: 120
					},
					{
						label: '买家备注',
						prop: 'buyerMsg',
						width: 120
					},
					{
						label: '快递费',
						prop: 'actualShipmentAmount',
						width: 80
					},
					{
						label: '配送方式',
						prop: 'expressType',
						type: 'select',
						dicData: Dict.expressTypeEnum,
						width: 80
					},
					{
						label: '订单总金额',
						searchLabelWidth: 100,
						prop: 'totalPrice',
						slot: true,
						width: 100
					},
					{
						label: '支付时间',
						prop: 'oPayTime',
						width: 135
					},
					{
						label: '下单时间',
						prop: 'addTime',
						width: 135
					},
					{
						label: '业务发生区域',
						prop: 'regionalOrganizationStr',
						width: 120
					},
					{
						label: '业务发生单元',
						prop: 'businessUnitOrganizationStr',
						width: 120
					},
					{
						label: '业务发生项目',
						prop: 'itemOrganizationStr',
						width: 120
					},
					{
						label: '店铺账号ID',
						prop: 'tripartiteStoreId',
						width: 90
					},
					{
						label: '店铺类型',
						prop: 'storeTypeName',
						width: 100
					},
					{
						label: '店铺名称',
						prop: 'storeName',
						search: true,
						searchSpan:8,
						width: 200
					},
					{
						label: '店铺签约区域',
						prop: 'signingAreaName',
						width: 200
					},
					{
						label: '支付方式',
						prop: 'payWay',
						type: 'select',
						dicData: Dict.payWayEnum,
						width: 80
					},
					{
						search: true,
						label: '对账状态',
						type: 'select',
						width: 100,
						searchSpan:8,
						prop: 'reconciliationStatus',
						dicData: ReconciliationStatusEnum
					},
					{
						label: '签约区域',
						prop: 'storeSigningArea',
						value: 'storeSigningArea',
						searchSpan:8,
						search: true,
						defaultExpandAll:false,
						hide: true,
						dicUrl:'/base/organization/listTreeByUserOrganization',
						type: 'tree',
						props: {
							label: 'name',
							value: 'id',
							children: 'childrenNodes'
						},
					},
				]
			},
			dialogOrderGoodsVisible:false,
			orderFormGoodsResults:[],//订单下商品
			orderGood:{},
			//宝贝详情
			option1: {
				border: true,
				header: false,
				menu: false,
				size: 'mini',
				align: 'center',
				menuAlign: 'center',
				column: [
					{
						label: '商品名称',
						prop: 'goodsName'
					},
					{
						label: '宝贝图片',
						prop: 'goodsMainPhotoUrl',
						width: 80,
						slot: true
					},
					{
						label: '商品大类',
						prop: 'goodsClassName1',
						width: 80
					},
					{
						label: '商品子类',
						prop: 'goodsClassName2',
						width: 80
					},
					{
						label: '商品小类',
						prop: 'goodsClassName3',
						width: 100
					},
					{
						label: '是否退款退货/仅退款',
						prop: 'orRefund',
						width: 170
					},
					{
						label: '商品类型',
						width: 100,
						prop: 'choiceType',
						dicData: Dict.GOODS_CHOICE_TYPE
					},
					{
						label: '商品规格',
						prop: 'specInfo',
						width: 120
					},
					{
						label: '商品单价',
						width: 70,
						prop: 'price'
					},
					{
						label: '商品数量',
						width: 70,
						prop: 'count'
					},
					{
						label: '商品小计',
						width: 70,
						prop: 'orderFormGoodsTotalPrice'
					},
					{
						label: '平台活动-团长分销拼团价格立减',
						prop: 'platformLeaderDistributionCut',
						width: 120
					},
					{
						label: '平台活动-余额抵扣',
						prop: 'platformBalanceDeduction',
						width: 120
					},
					{
						label: '平台活动-优惠券优惠',
						prop: 'mallCouponAmount',
						width: 120
					},
					{
						label: '平台活动汇总',
						prop: 'platformActivitySummary',
						width: 120
					},
					{
						label: '商家活动-秒杀立减',
						prop: 'storeSpikeCut',
						width: 120
					},
					{
						label: '商家活动-满额立减',
						prop: 'fullCutPrice',
						width: 120
					},
					{
						label: '商家活动-优惠券立减',
						prop: 'storeCouponAmount',
						width: 120
					},
					{
						label: '商家活动-团长分销拼团立减',
						prop: 'storeLeaderDistributionCut',
						width: 120
					},
					{
						label: '商家活动-普通拼团活动立减',
						prop: 'storeCommonGroup',
						width: 120
					},
					{
						label: '商家活动汇总',
						prop: 'storeActivitySummary',
						width: 120
					},
					{
						label: '商家活动-满赠 是否 ',
						prop: 'orGift',
						width: 120
					},
					{
						label: '商品约定结算价',
						width: 100,
						prop: 'purchasePrice'
					},
					{
						label: '商品提佣比例',
						width: 100,
						prop: 'commissionRate'
					},
					{
						label: '公司所得差额',
						prop: 'commissionValue',
						width: 100
					},
					{
						label: '退款金额',
						prop: 'refundPrice',
						width: 70
					}
					// {
					// 	label: "退款状态",
					// 	prop: "user1",
					// 	width:70,
					// },
				]
			},
			data: [],
			addTimeBegin: '',
			addTimeEnd: ''
		};
	},
	watch: {
		'form1.invoiceType'() {
			if (this.form1.invoiceType == 0) {
				//个人发票
				this.optionDetail.group[4].column[6].display = true;
				this.optionDetail.group[4].column[7].display = false;
				this.optionDetail.group[4].column[8].display = true;
			} else if (this.form1.invoiceType == 2) {
				//不开发票
				this.optionDetail.group[4].column[6].display = false;
				this.optionDetail.group[4].column[7].display = false;
				this.optionDetail.group[4].column[8].display = false;
			} else if (this.form1.invoiceType == 1) {
				this.optionDetail.group[4].column[6].display = true;
				this.optionDetail.group[4].column[7].display = true;
				this.optionDetail.group[4].column[8].display = true;
			}
		}
	},
	computed: {
		...mapGetters(['permission', 'userInfo']),
		permissionList() {
			return {};
		}
	},
	methods: {
		outExcel() {
			let token = getToken();
			let storeName = this.query.storeName === undefined ? '' : this.query.storeName;
			let addressMobile = this.query.addressMobile === undefined ? '' : this.query.addressMobile;
			let orderId = this.query.orderId === undefined ? '' : this.query.orderId;
			let userName = this.query.userName === undefined ? '' : this.query.userName;
			let payWay = this.query.payWay === undefined ? '' : this.query.payWay;
			let orderStatus = this.query.orderStatus === undefined ? '' : this.query.orderStatus;
			let reconciliationStatus = this.query.reconciliationStatus === undefined ? '' : this.query.reconciliationStatus;
			let addTimeBegin = this.query.addTimeBegin === undefined ? '' : this.query.addTimeBegin;
			let addTimeEnd = this.query.addTimeEnd === undefined ? '' : this.query.addTimeEnd;
			window.location.href =
				'/order/orderForm/outExcel?token=' +
				token +
				'&storeName=' +
				storeName +
				'&addressMobile=' +
				addressMobile +
				'&orderId=' +
				orderId +
				'&userName=' +
				userName +
				'&payWay=' +
				payWay +
				'&reconciliationStatus=' +
				reconciliationStatus +
				'&orderStatus=' +
				orderStatus +
				'&addTimeBegin=' +
				addTimeBegin +
				'&addTimeEnd=' +
				addTimeEnd;
		},
		outLittleExcel() {
			if (this.idList.length > 0){
			let token = getToken();
			let storeName = this.query.storeName === undefined ? '' : this.query.storeName;
			let addressMobile = this.query.addressMobile === undefined ? '' : this.query.addressMobile;
			let orderId = this.query.orderId === undefined ? '' : this.query.orderId;
			let userName = this.query.userName === undefined ? '' : this.query.userName;
			let payWay = this.query.payWay === undefined ? '' : this.query.payWay;
			let orderStatus = this.query.orderStatus === undefined ? '' : this.query.orderStatus;
			let reconciliationStatus = this.query.reconciliationStatus === undefined ? '' : this.query.reconciliationStatus;
			let addTimeBegin = this.query.addTimeBegin === undefined ? '' : this.query.addTimeBegin;
			let addTimeEnd = this.query.addTimeEnd === undefined ? '' : this.query.addTimeEnd;
			let addressTrueName=this.query.addressTrueName===undefined?'':this.query.addressTrueName;
			let idList = this.idList;
			let regionalOrganizationId=this.query.regionalOrganizationId===undefined?'':this.query.regionalOrganizationId;
			let businessUnitOrganizationId=this.query.businessUnitOrganizationId===undefined?'':this.query.businessUnitOrganizationId;
			let itemOrganizationId=this.query.itemOrganizationId===undefined?'':this.query.itemOrganizationId;
			window.location.href =
					'/order/orderForm/outOrderGoodsExcel?token=' +
					token +
					'&storeName=' +
					storeName +
					'&addressMobile=' +
					addressMobile +
					'&orderId=' +
					orderId +
					'&userName=' +
					userName +
					'&payWay=' +
					payWay +
					'&reconciliationStatus=' +
					reconciliationStatus +
					'&orderStatus=' +
					orderStatus +
					'&addTimeBegin=' +
					addTimeBegin +
					'&addTimeEnd=' +
					addTimeEnd+
					'&idList=' +
					idList+
			        '&addressTrueName='+addressTrueName+
					'&regionalOrganizationId='+regionalOrganizationId+
					'&businessUnitOrganizationId='+businessUnitOrganizationId+
					'&itemOrganizationId='+itemOrganizationId;
			setTimeout(()=>{
					this.idList = [];
					this.onLoad(this.page, this.query);
				},500)
			}else {
				this.$message({
					type: "error",
					message: "至少选择一笔数据"
				});
			}
			},
		outOrderGoodsExcel() {
			let token = getToken();
			let storeName = this.query.storeName === undefined ? '' : this.query.storeName;
			let addressMobile = this.query.addressMobile === undefined ? '' : this.query.addressMobile;
			let orderId = this.query.orderId === undefined ? '' : this.query.orderId;
			let userName = this.query.userName === undefined ? '' : this.query.userName;
			let payWay = this.query.payWay === undefined ? '' : this.query.payWay;
			let orderStatus = this.query.orderStatus === undefined ? '' : this.query.orderStatus;
			let reconciliationStatus = this.query.reconciliationStatus === undefined ? '' : this.query.reconciliationStatus;
			let addTimeBegin = this.query.addTimeBegin === undefined ? '' : this.query.addTimeBegin;
			let addTimeEnd = this.query.addTimeEnd === undefined ? '' : this.query.addTimeEnd;
			let addressTrueName=this.query.addressTrueName===undefined?'':this.query.addressTrueName;
			let regionalOrganizationId=this.query.regionalOrganizationId===undefined?'':this.query.regionalOrganizationId;
			let businessUnitOrganizationId=this.query.businessUnitOrganizationId===undefined?'':this.query.businessUnitOrganizationId;
			let itemOrganizationId=this.query.itemOrganizationId===undefined?'':this.query.itemOrganizationId;
			window.location.href =
					'/order/orderForm/outOrderGoodsExcel?token=' +
					token +
					'&storeName=' +
					storeName +
					'&addressMobile=' +
					addressMobile +
					'&orderId=' +
					orderId +
					'&userName=' +
					userName +
					'&payWay=' +
					payWay +
					'&reconciliationStatus=' +
					reconciliationStatus +
					'&orderStatus=' +
					orderStatus +
					'&addTimeBegin=' +
					addTimeBegin +
					'&addTimeEnd=' +
					addTimeEnd+
					'&addressTrueName='+addressTrueName+
					'&regionalOrganizationId='+regionalOrganizationId+
					'&businessUnitOrganizationId='+businessUnitOrganizationId+
					'&itemOrganizationId='+itemOrganizationId;
		},
		rowStyle() {
			return {
				backgroundColor: '#f3f3f3',
				color: '#333333'
			};
		},
		//选择项目
		changeAreaForRongChuang(parentId, lev) {
		    //省级选择框
		    if (lev == 3) {//区域
		        getOrganizationListByLevel(parentId, lev).then(res => {
		            if (lev == 3) {
		                this.rcityId = "";
		                this.projectId = "";
		                this.rcitys = res.data.data;
		            }
		        })
		    }
		    if (lev == 4) {//城市
		        getOrganizationListByLevel(parentId, lev).then(res => {
		            if (lev == 4) {
		                this.projects = res.data.data;
		            }
		        })
		    }
		},
		getBeginTime() {
			if (this.addTimeEnd) {
				if (this.addTimeBegin > this.addTimeEnd) {
					this.$message({
						type: 'error',
						message: '开始时间不能大于结束时间'
					});
					this.addTimeBegin = '';
				}
			}
		},
		getEndTime() {
			if (this.addTimeBegin) {
				if (this.addTimeBegin > this.addTimeEnd) {
					this.$message({
						type: 'error',
						message: '结束时间不能小于开始时间'
					});
					this.addTimeEnd = '';
				}
			}
		},
		//查看订单下商品
		viewOrderGoods(id){
			let obj = {
				ofId: id
			};
			getOrderFormGoods(obj).then(res => {
				if(res.data.code==200  ){
					if(res.data.data.length>0){
						res.data.data.forEach(item => {
							item.purchasePrice = item.goodsSkuData.purchasePrice;
							item.commissionRate = item.goodsSkuData.commissionRate;
							item.commissionValue = item.goodsSkuData.commissionValue;
						});
					}
					this.orderFormGoodsResults =res.data.data
					this.dialogOrderGoodsVisible = true
				}else{
					this.$message.warning(res.data.message)
				}
			});
		},
		closeOrderGoods(){
			this.orderFormGoodsResults = []
			this.dialogOrderGoodsVisible = false
		},
		viewDetail(id, userName,storeWillCallId) {
			getDetail(id).then(res => {
				if (res.data.code == 200) {
					let data = res.data.data;
					this.form1.userName = userName;
					this.form1.regionalOrganizationStr = data.regionalOrganizationStr;
					this.form1.businessUnitOrganizationStr = data.businessUnitOrganizationStr;
					this.form1.itemOrganizationStr = data.itemOrganizationStr;
					this.form1.orderId = data.orderForm.orderId;
					this.form1.addTime = data.orderForm.addTime;
					this.form1.payWay = data.orderForm.payWay;
					this.form1.payFormId = data.orderForm.payFormId || ''
					this.form1.pfCode = data.orderForm.pfCode || ''
					this.form1.oPayTime = data.orderForm.oPayTime;
					this.form1.storeName = data.orderForm.storeName;
					this.form1.storeTypeName = data.store.storeTypeName;
					this.form1.tripartiteStoreId = data.store.tripartiteStoreId;
					this.form1.orderStatus = data.orderForm.orderStatus;
					this.form1.storeWillInfo = data.orderForm.storeWillCallName;
					this.form1.sellerPhoneNumber = data.orderForm.sellerPhoneNumber;
					this.form1.sellerAddress = data.orderForm.sellerAddress;
					data.orderDistributionList.forEach(item=>{
						if(item.orderFormGoodsResultList!=""){
							item.orderFormGoodsResultList.forEach(good=>{
								good.purchasePrice = good.goodsSkuData.purchasePrice
								good.commissionRate = good.goodsSkuData.commissionRate
								good.commissionValue = good.goodsSkuData.commissionValue
							})
						}
					})
					this.form1.orderDistributionList = data.orderDistributionList;
					this.form1.goodsDetail = data.orderGoodsList;
					this.form1.trueName = data.orderAddress.trueName;
					this.form1.zip = data.orderAddress.zip;
					this.form1.address = data.orderAddress.provinceAreaName + data.orderAddress.cityAreaName + data.orderAddress.countyAreaName;
					this.form1.areaInfo = data.orderAddress.areaInfo;
					this.form1.address = data.orderAddress.address;
					this.form1.mobile = data.orderAddress.mobile;
					this.form1.buyerMsg = data.orderFormInfoResultList[0].buyerMsg;
					this.form1.invoiceType = data.orderFormInfoResultList[0].invoiceType; //发票类型
					this.form1.invoiceTitle = data.orderFormInfoResultList[0].invoiceTitle; //发票抬头
					this.form1.invoiceTaxNum = data.orderFormInfoResultList[0].invoiceTaxNum; //纳税人识别号
					this.form1.invoiceEmail = data.orderFormInfoResultList[0].invoiceEmail; //接收发票邮箱
					this.form1.invoiceUploadResultMsg = data.orderFormInfoResultList[0].invoiceUploadResultMsg; //接收发票邮箱
					this.form1.invoiceUrl = data.orderFormInfoResultList[0].invoiceUrl; //三方链接
					this.form1.expressType = data.orderFormInfoResultList[0].expressType; //运输类型
					this.form1.expressCompanyName = data.orderFormInfoResultList[0].expressCompanyName; //物流公司名
					this.form1.shipCode = data.orderFormInfoResultList[0].shipCode; //快递单号
					this.form1.totalPrice = data.orderForm.totalPrice; //订单总价
					this.form1.lastAmount = data.orderFormAmount[0].lastAmount; //总付款
					this.form1.actualShipmentAmount = data.orderFormAmount[0].actualShipmentAmount; //运费
					this.form1.couponAmountPlatform = data.orderFormAmount[0].couponAmountPlatform; //平台优惠
					this.form1.fullCutAmount = data.orderFormAmount[0].fullCutAmount; //满减优惠fullDiscountAmount
					this.form1.fullDiscountAmount = data.orderFormAmount[0].fullDiscountAmount; //满折优惠
					this.form1.couponAmountStore = data.orderFormAmount[0].couponAmountStore; //店铺优惠
					this.form1.isUseIntegral = data.orderFormAmount[0].isUseIntegral; //是否使用积分抵扣
					this.form1.integralTotalAmount = data.orderFormAmount[0].integralTotalAmount; //积分抵扣金额
					this.form1.historyLog = data.logList; //操作历史
					this.form1.orderType = data.orderForm.orderType; //订单类型
					this.form1.platformReward = data.platformReward;
					this.form1.storeReward = data.storeReward;
					console.log(this.form1.historyLog);
					if(this.form1.invoiceUrl==''&&this.form1.invoiceUploadResultMsg!=''){
						this.optionDetail.group[4].column[9].display = true
					}else{
						this.optionDetail.group[4].column[9].display = false
					}
					getStoreWillCallId(storeWillCallId).then(res1=>{
						this.form1.phone = res1.data.data.phone
						this.form1.storeWillInfo = res1.data.data.storeName
						this.form1.storeWilladdress = res1.data.data.address

					})
					if(this.form1.payFormId.trim().length!=0) {
						getCallbackIdByPayFormId({payFormId:this.form1.payFormId}).then(request=>{
							if(request.data.code==200) {
								this.form1.callbackId = request.data.data.callbackId
								console.log('callbackId',this.form1.callbackId)
							}
						})
					}
					if(this.form1.expressType==0){//自提
						this.optionDetail.group[4].display=false
						this.optionDetail.group[6].display=true
					}else{
						this.optionDetail.group[4].display=true
						this.optionDetail.group[6].display=false
					}
					if (data.orderDistributionList.length > 0) {
						this.form1.distributionSn = data.orderDistributionList[0].distributionSn
						this.form1.distributionDesc = data.orderDistributionList[0].distributionDesc || ' '
						this.form1.storeWillCallTime = data.orderDistributionList[0].storeWillCallBeginTime.split(" ",1) +" -- "+ data.orderDistributionList[0].storeWillCallEndTime.split(" ",1) || ' '
					}
					this.dialogDeatilVisible = true;
				} else {
					this.$message.error(res.data.message)
					return
				}
			});
		},
		closeDetailDialog() {
			this.form1={};
			this.dialogDeatilVisible = false;
		},
		// 选中状态变化时
		selectionChange(list) {
			this.allMoney= 0;
			let tempAllMoney = 0;
			list.forEach(item => {
				tempAllMoney+=item.lastTotalAmount
			});
			tempAllMoney = Number(tempAllMoney);
			this.allMoney =Math.round(tempAllMoney * 100) / 100
			let idList = []
			if (list.length > 0) {
				for (let item of list) {
					idList.push(item.id)
				}
				console.log(idList)
				this.idList = idList
			} else {
				this.idList = [];
			}
		},

		searchReset() {
			this.query = {};
			this.addTimeBegin = '';
			this.addTimeEnd = '';
			this.cityId = ''
			this.rareaId = ''
			this.rcityId = ''
			this.projectId = ''
			this.onLoad(this.page);
		},
		searchChange(params) {
			this.page.currentPage = 1;
			this.query.addTimeBegin = this.addTimeBegin;
			this.query.addTimeEnd = this.addTimeEnd;
			params.regionalOrganizationId = this.rareaId ||''
			params.businessUnitOrganizationId = this.rcityId||''
			params.itemOrganizationId = this.projectId||''
			this.query = params
			this.onLoad(this.page);
		},
		currentChange(currentPage) {
			this.page.currentPage = currentPage;
		},
		sizeChange(pageSize) {
			this.page.pageSize = pageSize;
		},
		refreshChange() {
			this.query.addTimeBegin = this.addTimeBegin;
			this.query.addTimeEnd = this.addTimeEnd;
			this.onLoad(this.page);
		},

		onLoad(page, params = {}) {
			params.orderType = this.orderType;
			this.loading = true;
			getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
				if (res.data.code == 200) {
					this.loading = false;
					const data = res.data;
					this.page.total = data.count;
					this.data = data.data;
				}
			});
			getOrganizationListByLevel(2, 2).then(res => {
			    this.rareas = res.data.data;
			})
		}
	}
};
</script>

<style>
	.btnRow {
		position: relative;
		bottom: 51px;
		left: 10px;
	}
	.allMoney{
		margin-left: 5px;
	}
	.loading_icon {
		width: 30px;
		margin: auto;
	}
	.drawerHeader {
		font-size: 17px;
		padding: 30px 20px;
	}
</style>
